package com.appscomm.bluetoothdemo.application;

import android.app.Application;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothManager;
import android.content.Context;
import android.os.Handler;

import org.xutils.x;

/**
 * Created by Administrator on 2016/6/8.
 */
public class BaseApplication extends Application{

    public static BluetoothAdapter bluetoothAdapter;
    private static Context	mContext;
    private static Handler	mHandler;
    private static long		mMainThreadId;
    private static Thread	mMainThread;

    public static Context getContext() {
        return mContext;
    }

    public static Handler getHandler() {
        return mHandler;
    }

    public static long getMainThreadId() {
        return mMainThreadId;
    }

    public static Thread getMainThread() {
        return mMainThread;
    }

    @Override
    public void onCreate() {// 程序入口方法
        // 创建一些常见的变量

        // 1.上下文
        mContext = getApplicationContext();

        // 2.创建一个handler
        mHandler = new Handler();

        // 3.得到一个主线程id
        mMainThreadId = android.os.Process.myTid();

        // 4.得到主线程
        mMainThread = Thread.currentThread();
        super.onCreate();
        x.Ext.init(this);       //init xutils3.0
        initBluetoothAdapter();
    }

    private void initBluetoothAdapter() {
        BluetoothManager manager = (BluetoothManager)getSystemService(Context.BLUETOOTH_SERVICE);
        bluetoothAdapter = manager.getAdapter();
    }
}
